package org.zhangchao.poi.excel.operate;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.zhangchao.poi.excel.common.XCell;
import org.zhangchao.poi.excel.interceptor.ExcelBuildModelHandlerInterceptor;
import org.zhangchao.poi.excel.interceptor.ExcelHandlerInterceptorStack;

/**
 * 
 * @author ZhangChao
 *
 * @param <E>
 */
public class ExcelBuildModelOperate<E> extends ExcelBaseOperate<E> {

	/**
	 * 构建处理器
	 * @param fileName
	 * @throws InvalidFormatException
	 * @throws IOException
	 */
	public ExcelBuildModelOperate(String fileName) throws InvalidFormatException, IOException {
		super(fileName);
	}
	
	/**
	 * 构建处理器
	 * @param file
	 * @throws InvalidFormatException
	 * @throws IOException
	 */
	public ExcelBuildModelOperate(File file) throws InvalidFormatException, IOException {
		super(file);
	}

	/**
	 * 构建处理器
	 * @param inp
	 * @throws InvalidFormatException
	 * @throws IOException
	 */
	public ExcelBuildModelOperate(InputStream inp) throws InvalidFormatException, IOException {
		super(inp);
	}
	
	/**
	 * 构建处理器
	 * @param fileName
	 * @param clazz
	 * @param headerdStartCell
	 * @param dataStartCell
	 * @throws InvalidFormatException
	 * @throws IOException
	 */
	public ExcelBuildModelOperate(String fileName, Class<?> clazz, XCell headerdStartCell, XCell dataStartCell) throws InvalidFormatException, IOException {
		super(fileName);
		init(clazz, headerdStartCell, dataStartCell);
	}
	
	/**
	 * 构建处理器
	 * @param file
	 * @param clazz
	 * @param headerdStartCell
	 * @param dataStartCell
	 * @throws InvalidFormatException
	 * @throws IOException
	 */
	public ExcelBuildModelOperate(File file, Class<?> clazz, XCell headerdStartCell, XCell dataStartCell) throws InvalidFormatException, IOException {
		super(file);
		init(clazz, headerdStartCell, dataStartCell);
	}

	/**
	 * 构建处理器
	 * @param inp
	 * @param clazz
	 * @param headerdStartCell
	 * @param dataStartCell
	 * @throws InvalidFormatException
	 * @throws IOException
	 */
	public ExcelBuildModelOperate(InputStream inp, Class<?> clazz, XCell headerdStartCell, XCell dataStartCell) throws InvalidFormatException, IOException {
		super(inp);
		init(clazz, headerdStartCell, dataStartCell);
	}
	
	/**
	 * 初始化设置
	 */
	private void init(Class<?> clazz, XCell headerdStartCell, XCell dataStartCell) {
		//穿件拦截器栈
		setHandlerStack(new ExcelHandlerInterceptorStack());
		//excel 拦截器--把excle行封装成对象
		ExcelBuildModelHandlerInterceptor ebmhi = new ExcelBuildModelHandlerInterceptor(clazz, headerdStartCell,  dataStartCell);
		getHandlerStack().add(ebmhi);
	}
	
}
